package com.hspedu.newData.dmsxl.动态规划.基础;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-23 
 * @Version: 1.0
 */

public class LC509斐波那契数 {

    // 递归求解
    public int fib(int n) {
        if (n < 2){
            return n;
        }
        return fib(n-1) + fib(n-2);
    }

    // 动态规划求解
    public int fib1(int n){
        int[] dp = new int[n + 1];
        dp[0] = 0;
        dp[1] = 1;

        for (int i = 2; i < n+1; i++) {
            dp[i] = dp[i-1] + dp[i-2];
        }
        return dp[n];
    }


    @Test
    public void test() {
        // 测试代码
        int fib = fib(5);
        int i = fib1(5);
        System.out.println("------");

    }



}
